package two;

public class A023 {

    /**
     * 反转链表
     * @param head
     * @return
     */
    public ListNode reverseList(ListNode head) {
        //使用虚拟头结点，头插法
        if(head==null || head.next==null) return head;
        ListNode newHead = new ListNode();
        ListNode cur = head;
        while(cur!=null) {
            ListNode next = cur.next;
            cur.next = newHead.next;
            newHead.next = cur;
            cur = next;

        }
        return newHead.next;
    }

}
